home *** CD-ROM | disk | FTP | other *** search
- head 1.43;
- access;
- symbols
- fontscreen:1.41
- good:1.41;
- locks; strict;
- comment @ * @;
-
-
- 1.43
- date 94.12.05.03.32.28; author jsshephe; state Exp;
- branches;
- next ;
-
-
- desc
- @original
- @
-
-
- 1.43
- log
- @Put up a file requester if the show icon was launched from Workbench with no other selected files.
- @
- text
- @/* Show by Jeff Shepherd
- * Compiled using GCC2.6.0 and my makemake program
- * Uses libnix. ie NO ixemul.library
- * This allows the inclusion of the WBStartup message
- */
-
- /*
- * $Revision: 1.42 $
- * $Id: show.c,v 1.42 1994/12/04 23:30:45 jsshephe Exp jsshephe $
- * $Log: show.c,v $
- * Revision 1.42 1994/12/04 23:30:45 jsshephe
- * Added inclusion of libraries/gadtools.h
- *
- * Revision 1.41 1994/11/27 21:58:46 jsshephe
- * Changed the calls to Error() sinced it was changed in misc.c.
- *
- * Revision 1.40 1994/11/27 04:03:04 jsshephe
- * Now prints usage if the command line is invalid (CLI only).
- * Process tooltypes for SHOWSUFFIX for workbench use.
- *
- * Revision 1.30 1994/08/19 19:39:48 jsshephe
- * Made show look for any suffix, not just those starting with '.'
- *
- * Revision 1.20 1994/08/18 21:29:57 jsshephe
- * Can now load preferences file
- * Can now do asynchonous commands by "run >NIL: command filename"
- *
- * Revision 1.11 1994/08/12 03:25:56 jsshephe
- * added -f option to change default suffix recognition
- *
- * Revision 1.1 1994/08/12 03:02:56 jsshephe
- * Initial revision
- *
- */
-
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <libraries/gadtools.h>
- #include <libraries/asl.h>
- #include <dos/dostags.h>
- #include <workbench/startup.h>
- #include <workbench/workbench.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include "showprefs.h"
-
- #include <clib/alib_protos.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/icon.h>
- #include <proto/asl.h>
-
- #define DIVIDE_STRING ";;" /* string that separates multiple commands */
- #define DIVIDE_STRING_LEN 2 /* strlen(DIVIDE_STRING) */
-
- /* protos */
- LONG ExecuteCommand(char *, char *, BOOL);
- void panic(char *, int);
- void ParseWB(struct WBStartup *);
- void ParseCommand(int, char **);
- void FileSelect(void);
- void WBExecuteCommand(char *);
-
- /* version string */
- char version[] = "\0$VER: show version 1.0";
-
- struct Library *IFFParseBase = NULL, *IconBase = NULL, *AslBase = NULL;
- struct List *Suffix_List;
-
- #ifdef __GNUC__
- extern struct WBStartup *_WBenchMsg;
- char __stdiowin[] = "KCON:0/150//230/Show/CLOSE/WAIT/AUTO";
- #endif
-
- int main(int argc, char **argv) {
-
- if ( !(IFFParseBase = OpenLibrary("iffparse.library",37)))
- panic ("Cannot open iffparse library version 37",1);
-
- if ( !(IconBase = OpenLibrary("icon.library",37)))
- panic ("Cannot open icon.library version 37",2);
-
- if ( !(AslBase = OpenLibrary("asl.library",37)))
- panic ("Cannot open asl.library version 37",3);
-
- if ( !(Suffix_List = AllocMem(sizeof(struct List),MEMF_PUBLIC|MEMF_CLEAR)))
- panic("Cannot allocate list",3);
-
- NewList(Suffix_List);
- Load("env:show.prefs",FALSE,NULL);
-
- #ifdef __GNUC__
- if (!_WBenchMsg) {
- #else
- if (!argc) {
- #endif
- /* came from CLI */
- ParseCommand(argc, argv);
- }
- else {
- /* came from WB */
- #ifdef __GNUC__
- ParseWB(_WBenchMsg);
- #else
- ParseWB((struct WBStartup *)argv);
- #endif
- }
- panic(NULL,0);
- }
-
- /* execute command with filename tagged on the end */
- /* As of now, Asynch does puts a "run >NIL:" in front of the command */
- LONG ExecuteCommand(char *command, char *filename, BOOL Asynch) {
- LONG retval;
- BOOL found_divide_char = FALSE;
- char *commandline = malloc(strlen(command) + strlen(filename)+12);
- char *end_of_command;
- char *exec_command;
- char *the_command;
-
- #ifdef debug
- printf("first command %s, filename %s\n",command,filename);
- #endif
- if (Asynch) {
- strcpy(commandline,"run >NIL: ");
- strcat(commandline,command);
- }
- else {
- strcpy(commandline,command);
- }
- the_command = commandline;
-
- #ifdef debug
- printf("Whole commandline %s\n",commandline);
- #endif
-
- do {
- end_of_command = strstr(the_command,DIVIDE_STRING);
-
- if (end_of_command != NULL) {
- *end_of_command = '\0';
- found_divide_char = TRUE;
- }
- else if (found_divide_char == FALSE) {
- strcat(commandline," ");
- strcat(commandline,filename);
- }
-
- #ifdef debug
- printf("before command: %s\n", the_command);
- #endif
-
- /* fill in %s if any */
- if (strstr(the_command,"\%s") != NULL) {
- exec_command = malloc(strlen(the_command) + strlen(filename)-2);
- strcpy(exec_command,the_command);
- sprintf(exec_command,the_command,filename);
-
- #ifdef debug
- printf("after command: %s\n", exec_command);
- #endif
-
- retval=SystemTags(exec_command, TAG_END);
- free(exec_command);
- } /* if */
- else {
- #ifdef debug
- printf("after command: %s\n", the_command);
- #endif
- retval=SystemTags(the_command, TAG_END);
- }
-
- the_command = end_of_command + DIVIDE_STRING_LEN;
-
- } while (end_of_command != NULL);
-
- free(commandline);
- return retval;
- }
-
-
- /* cleanup time */
- void panic(char *error, int retval) {
- if (error)
- fprintf(stderr,"ERROR: %s\n",error);
-
- if (Suffix_List) {
- Destroy_List(Suffix_List);
- FreeMem(Suffix_List,sizeof(struct List));
- }
-
- if (AslBase)
- CloseLibrary(AslBase);
-
- if (IconBase)
- CloseLibrary(IconBase);
-
- if (IFFParseBase)
- CloseLibrary(IFFParseBase);
-
- exit(retval);
- }
-
- void ParseCommand(int argc, char **argv) {
- int j;
- char error[MAX_LENGTH];
- struct SuffixList *SNode;
-
- if (argc < 2) {
- printf("USAGE: %s [-f suffix] filename [[-f suffix]filename2...]\n",argv[0]);
- exit(2);
- }
-
- for (j=1; j < argc; j++) {
- if (*argv[j] == '-') {
-
- /* I use a switch statement to allow further expansion */
- switch (argv[j][1]) {
-
- /* change default handling of suffix */
- case 'f':
- if (argv[j][2]) {
- SNode = (struct SuffixList *)FindName(Suffix_List,&argv[j][2]);
- }
- else {
- if (++j >= argc) panic("Bad command line",2);
- SNode = (struct SuffixList *)FindName(Suffix_List,argv[j]);
- }
- j++;
- if (j >= argc)
- panic("Bad command line",2);
-
- /* Make sure the user specified a suffix that is defined */
- if (SNode) {
- ExecuteCommand(SNode->command, argv[j], SNode->Asynch);
- }
- else {
- sprintf(error,"suffix in %s not found",argv[j]);
- panic(error,3);
- } /* if */
- break;
-
- } /* switch */
- } /* if */
- else {
- if (SNode = (struct SuffixList *)SearchSuffix(Suffix_List,argv[j])) {
- ExecuteCommand(SNode->command, argv[j], SNode->Asynch);
- }
- else {
- sprintf(error,"Suffix in %s not defined",argv[j]);
- panic(error,4);
- }/* if */
- } /* else */
- } /* for */
- } /* ParseCommand() */
-
- /* parse workbench startup message */
- void ParseWB(struct WBStartup *WBMsg) {
- struct WBArg *args = WBMsg->sm_ArgList;
- int i;
- char dir[2*MAX_LENGTH];
-
- /* pass over the argument for "show" */
- args++;
-
- /* bring up ASL Requester if just clicked on icon */
- if (WBMsg->sm_NumArgs == 1) {
- FileSelect();
- }
- else {
-
- /* go over the passed in files and "show" them */
- for(i=1; i < WBMsg->sm_NumArgs; i++, args++) {
- /* get absolute path for filename */
- NameFromLock(args->wa_Lock,dir,MAX_LENGTH);
- AddPart(dir,args->wa_Name,MAX_LENGTH);
- WBExecuteCommand(dir);
- } /* for */
- } /* if */
- }
-
- void FileSelect(void) {
- struct FileRequester *fr;
- struct WBArg *args;
- int i;
- char dir[MAX_LENGTH];
-
- if (!(fr = AllocAslRequestTags(ASL_FileRequest,
- ASLFR_TitleText, "Select File...",
- ASLFR_PositiveText, "Show",
- ASLFR_Flags1, FRF_DOMULTISELECT,
- ASLFR_Flags2, FRF_REJECTICONS,
- TAG_DONE ))) {
- Error("Cannot allocate ASL requester");
- }
-
- while (AslRequest(fr,NULL)) {
- if (fr->rf_NumArgs) {
- for (i=0, args = fr->rf_ArgList; i < fr->rf_NumArgs; i++,args++) {
- NameFromLock(args->wa_Lock,dir,MAX_LENGTH);
- AddPart(dir,args->wa_Name,MAX_LENGTH);
- WBExecuteCommand(dir);
- } /* for */
- } /* if */
- else {
- strcpy(dir,fr->rf_Dir);
- AddPart(dir,fr->rf_File,MAX_LENGTH);
- WBExecuteCommand(dir);
- } /* if */
- } /* if */
- FreeAslRequest(fr);
- }
-
- /* Executes the command by first search for the tooltype array then its suffix */
- void WBExecuteCommand(char *dir) {
- struct DiskObject *dkobj;
- char *tooltype_suffix;
- char *filename = FilePart(dir);
- BOOL Executed_Command = FALSE; /* used just in case tooltype was not found */
- static char error[MAX_LENGTH];
- struct SuffixList *SNode;
-
- if ((dkobj=GetDiskObject(dir)) != NULL) {
- if ((tooltype_suffix = FindToolType(dkobj->do_ToolTypes,"SHOWSUFFIX"))) {
- Executed_Command = TRUE;
- if (SNode = (struct SuffixList *)FindName(Suffix_List, tooltype_suffix)) {
- ExecuteCommand(SNode->command,dir,SNode->Asynch);
- } /* if */
- else {
- sprintf(error,"Suffix in tooltypes of file %s not defined.",filename);
- Error(error);
- } /* if */
- } /* if */
- FreeDiskObject(dkobj);
- } /* if */
-
- /* just in case tooltype wasn't found, execute suffix search */
- if (Executed_Command == FALSE) {
- if (SNode = (struct SuffixList *)SearchSuffix(Suffix_List,filename)) {
- ExecuteCommand(SNode->command,dir,SNode->Asynch);
- }
- else {
- sprintf(error,"Suffix in %s not defined.",filename);
- Error(error);
- }
- } /* if */
- }
-
-
-
-
-
- @
-